#include "StdAfx.h"
#include "AutoLock.h"

ProcessLock::ProcessLock(wstring key)
{
	event = CreateEvent(0, FALSE, TRUE, key.c_str());
	assert(event);
	WaitForSingleObject(event, INFINITE);

}

ProcessLock::~ProcessLock(void)
{
	SetEvent(event);
	CloseHandle(event);
}

wstring GetProcessIDStr(){
	DWORD id = GetCurrentProcessId();
	return boost::lexical_cast<wstring>(id);
}

ThreadLock::ThreadLock(wstring key):ProcessLock(GetProcessIDStr() + key){}